$(document).ready(function() {
	
	$.ajax({
		url : 'NewsSrvl' , 
		type : "POST",
		data : {process_type : "getNewsTypeS"},
		dataType : "json",
		anync:false,
		success: function(data){
			if(data.topic.length==0){
				var news ='<div class="news-detail clearfix form-group">';
				news  += '<div class=" mr-10 pull-left" style=" height: 100px;">';
				news  += '</div>';
				news  += '<div class="pull-left row col-sm-12">';
				news  += '<h4 class="text-center">ไม่มีข่าวสารในช่วงนี้</h4>';
				news  += '<small></small>';
				news  += '<div class="text-right mt-10">';
				news  += '</div>';
				news  += '</div>';
				$("#news-list").append(news);
				
			}else{
				for (var i = 0; i < data.topic.length; i++) {
					var list_news = '<div class="news-detail clearfix">';
					list_news  += '<div class="media-img mr-10 pull-left">';
					list_news  += '<img src="/CS/assets/images/new/'+data.url[i]+'" width="100%" style=" height: 120px;" />';
					list_news  += '</div>';
					list_news  += '<div class="media-info pull-left">';
					list_news  += '<h4><a href="#" >'+data.topic[i]+'</a></h4>';
					list_news  += '<small>'+data.detail[i]+'</small>';
					list_news  += '<div class="text-right mt-10">';
					list_news  += '<a onclick="ShowDetail(\'' +i+ '\', \'' +data.topic[i] + '\', \'' +data.detail[i] + '\', \'' +data.url[i] + '\');" href="#" >อ่านเพิ่ม. . .</a></div>';
					list_news  += '</div>';
					list_news  += '</div>';
					
					$("#news-list").append(list_news);
				}
			}
			
		}
	});
});

function  ShowDetail(list,topic,detail,url){
	$.ajax({
		url : 'NewsSrvl' , 
		type : "POST",
		data : {
			process_type : "getDeatailTypeS" , 
			topic : topic, 
		},
		dataType : "json",
		success: function(data){
			
			document.getElementById("image-news").innerHTML ='<img src="/CS/assets/images/new/'+url+'"/>';
			document.getElementById("topic").innerHTML =topic;
			document.getElementById("DetailNews").innerHTML ='<div class="text-left">'+data.datails+'</div>';
			$("#Detail-new").modal('show');
		}
	});
}

